<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<link rel="shortcut icon" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/logo.png"/>
	<meta name="apple-mobile-web-app-capable" content="no" />
	<title>{{.title}}</title>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
    <link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/font/iconfont.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/all.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/app.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/other/ydui.css?v" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/dropload.css" rel="stylesheet" />
</head>
<style>
	.filter dl:last-child i{font-size: 7pt}
	.noproduct{height: calc(100vh - 55px);background: url('/static/wechat/img/noproduct.png') no-repeat;background-size: 63%;background-position: center;
	display: {{if .info}}none{{else}}block{{end}}}
	.filter .ac dt{color:#e31939;}
	#price{position: relative;}
	#pirce dt{position: relative;}
	#price .iconfont{font-size: 6pt !important;margin: 0 !important;}
	#price #down{position: absolute;bottom:calc(6pt - 12px);left: 0}
	#price #up{position: absolute;top:calc(6pt - 12px);left: 0}
	#price dt div{position: absolute;height: 40px;width:6pt;top: 0;left: calc(50% + 10pt + 3px);}
	.icon-home2{position: fixed;right: 15px;bottom: 15px;background: #e31939;border-radius: 50%;color: #fff;width: 40px;height: 40px;padding: 7.5px}
	.icon-home2:before{font-size: 25px;}
	.PrdLineStyle{min-height: 100vh}
	.PrdLineStyle .goto{position: relative;}
	.PrdLineStyle .goto .scadd{color:#e54242;position:absolute;bottom: 8px;right:13px;font-size: 18pt}
	.PrdLineStyle dd{width: calc(100% - 30vw - 10px);float: right;}
	.PrdLineStyle dl .x{position: absolute;top: 0px;right:0px;z-index: 9;width: 30px;height: 30px;}
	.search {position: fixed;top: 0;width: 100%;height: 45px;padding: 0 45px;border-bottom: solid 1px #efefef;}
	.search .back {position: absolute;left: 0;width: 45px;height: 100%;line-height: 45px;text-align: center;font-size: 18px;font-weight: 800;}
	.search input[type=search] {width: 100%;margin-top: 7.5px;}
	.filter {margin-top: 46px;}
</style>
<body>
	<!-- <span class="mui-icon iconfont icon-home2 goto" href="/mobile/index"></span> -->
	<div class="search">
		<div class="back iconfont icon-fanhui1" onclick="history.go(-1)"></div>
		<form action="/mobile/column/search_result" method="get">
			<input type="search" placeholder="请输入搜索关键词" name="keywords" id="key">
			<input type="submit" style="display:none;">
		</form>
	</div>
	<div class="filter">
		<dl class="{{if ne .status "3"}}ac{{end}} sort" data-status=''>
			<dt>综合</dt>
			<!-- <dd></dd> -->
		</dl>
		<dl class="sort" data-status='1' id="price">
			<dt>价格 <div><i class="iconfont" id="up">&#xe700;</i>
					<i class="iconfont" id="down">&#xe701;</i></div></dt>
			<!-- <dd></dd> -->
		</dl>
		<dl class="sort" data-status='2'>
			<dt>销量</dt>
			<!-- <dd></dd> -->
		</dl>
		<dl class="{{if eq .status "3"}}ac{{end}} sort" data-status='3'>
			<dt>最新</dt>
			<!-- <dd></dd> -->
		</dl>
	</div>
	<div class="PrdLineStyle">
		{{range $k,$v:=.info}}
		<dl class="goto" data-price="{{$v.price}}" data-sellnum="{{$v.sellnum}}" data-sort="{{$k}}" data-addtime="{{$v.addtime}}">
			<dt class="goto" href="/mobile/column/product_content?id={{$v.id}}"><img src="{{$v.pathname}}" alt=""></dt>
			<dd class="goto" href="/mobile/column/product_content?id={{$v.id}}">
				<p>{{$v.title}}</p>
				<p>{{range $v.keywords}}<span>{{.}}</span>{{end}}
				<p><span><span>&yen;</span>{{if $v.vprice}}{{$v.vprice}}{{else}}{{$v.price}}{{end}}</span>{{$v.sellnum}}人购买</p>
				<p>{{if $v.gname}}{{$v.gname}} {{else}}{{$.system.name}} {{end}} <a href="/mobile/index/shop?id={{.gid}}">进店<i class="iconfont">&#xe7bb;</i></a></p>
			</dd>
			<i class="iconfont scadd" data-id="{{$v.id}}" data-minbuy="{{$v.minbuy}}">&#xe619;</i>
			{{if eq $v.active 1}}
			<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/gbuy.png" class="x">
			{{else if eq $v.active 2}}
			<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/sales.png" class="x">
			{{end}}
		</dl>
		{{end}}
		<div class="noproduct"></div>
	</div>
	
</body>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/js/SUI.js"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/zepto.min.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/dropload.min.js"></script>
{{template "wechat/public/share.html" .}}
<script type="text/javascript" charset="utf-8">
		var status={{.status}};
		var keywords2='';
		var page = 2;
	function search(){
		document.getElementById("key").blur();
		keywords2=$('input[name="keywords"]').val()
		if(keywords2==""){
			return false;
		}else{
			// $('input[name="keywords"]').val('')
			searchajax()
			return false;
		}
		return false;
	}
	function searchajax(isd){
		page = 1
		$.ajax({
			url:window.location.href,
			data:{keywords2:keywords2,status:status,page:page},
			success:function(res){
				isclick = true
				var html=''
				if (res){
					for(var i=0;i<res.length;i++){
						html+=`<dl class="goto" data-price="`+res[i].price+`" data-sellnum="`+res[i].sellnum+`"  data-sort="`+i+`">
						<dt class="goto" href="/mobile/column/product_content?id=`+res[i].id+`"><img src="`+res[i].pathname+`" alt=""></dt> <dd class="goto" href="/mobile/column/product_content?id=`+res[i].id+`">
						<p>`+res[i].title+`</p><p>`
						if (res[i].keywords){
							for(var j=0;j<res[i].keywords.length;j++){
								html+=`<span>`+res[i].keywords[j]+`</span>`
							}
						}
						html+=`</p><p><span><span>&yen;</span>`
						if(res[i].vprice){
							html+=res[i].vprice
						}else{
							html+=res[i].price
						}
						html+=`</span>`+res[i].sellnum+`人购买</p> </dd><i class="iconfont scadd" data-minbuy="`+res[i].minbuy+`" data-id="`+res[i].id+'">&#xe619;</i>'
						if (res[i].active==1){
						html+='<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/gbuy.png" class="x"></dl>'
						}else if(res[i].active==2){
							html+='<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/sales.png" class="x"></dl>'
						}else{
							html+='</dl>'
						}
						// https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/
					}
					if (page>1) {
						$('.noproduct').before(html)
					} else {
						html += `<div class="noproduct"></div>`
						$('.PrdLineStyle').html(html)
					}
					page ++
					dropload()
				}else{
					if (page>1) {
						mui.toast("没有更多了!")
					} else {
						$('.noproduct').css('display','block')
					}
				}
			},
			error:function(){
				mui.toast("网络慢，请重新刷新!");
			}
		})
	}
	// $('input[name="keywords"]').change(function(){
	// 	keywords2=$(this).val()
	// 	var id=$(this).siblings('input').val()
	// 	if(keywords2==""){
	// 		return
	// 	}else{
	// 		$(this).val('')
	// 		searchajax()
	// 	}
	// })
	var isclick = true
	$('.sort').click(function(){
		if (isclick) {
			isclick = false
			page=1
			if (status==$(this).attr('data-status')) {
				return false;
			};
			status=$(this).attr('data-status')
			if (status=='1'){
				$(this).attr('data-status',	0)
				$('#down').css('color','#333')
				$('#up').css('color','#e31939')
			}else if(status=='0'){
				$(this).attr('data-status',1)
				$('#up').css('color','#333')
				$('#down').css('color','#e31939')
			}else if(status==''||status=='2'||status=='3'){
				$('#up').css('color','#333')
				$('#down').css('color','#333')
			}
			$('#down').html('&#xe701;')
			$('#up').html('&#xe700;')
			$('.sort').attr('class','sort')
			$(this).attr('class','sort ac')
			searchajax()
		}
	})
// function sort(){
// 		var arr=[]
// 		$('.goto').each(function(){
// 			arr.push(this)
// 		})
// 		switch(status){
// 			case "":
// 			arr.sort(function(a,b){return parseInt(a.getAttribute('data-sort')) -  parseInt(b.getAttribute('data-sort'))});
// 			break;
// 			case "0":
// 			arr.sort(function(a,b){return parseFloat(b.getAttribute('data-price')) - parseFloat(a.getAttribute('data-price'))});
// 			break;
// 			case "1":
// 			arr.sort(function(a,b){return parseFloat(a.getAttribute('data-price')) - parseFloat(b.getAttribute('data-price'))});
// 			break;
// 			case "2":
// 			arr.sort(function(a,b){return parseInt(b.getAttribute('data-sellnum')) -  parseInt(a.getAttribute('data-sellnum'))});
// 			break;
// 			case "3":
// 			arr.sort(function(a,b){return Date.parse(new Date(b.getAttribute('data-addtime'))) -  Date.parse(new Date(a.getAttribute('data-addtime'))) });
// 			break;
// 		}
// 		$('.PrdLineStyle').html('')
// 		for(var i=0;i<arr.length;i++){
// 			$('.PrdLineStyle').append(arr[i])
// 		}
// 	}
function dropload(){
	$(window).unbind("scroll")
	clicknum = 0
$('.element').dropload({
    scrollArea : window,
    threshold: 2,
    loadDownFn : function(me){
    	mui.toast("加载中，请稍后~");
        $.ajax({
            type: 'GET',
            url: window.location.href,
            dataType: 'json',
            data:{page:page,status:status,keywords2:keywords2},
            success: function(res){
            	isclick = true
            	mui.closePopups()
                page+=1
               if(res){
              	    var godom=document.getElementsByClassName('goto')
              	    var k=parseInt(godom[godom.length-1].getAttribute('data-sort'))
                    for (var i=0;i<res.length;i++){
	             		k=k+1
	                    var dl = document.createElement('dl');
	                    dl.className="goto"
	                    // dl.setAttribute('href',"/mobile/column/product_content?id="+res[i].id)
	                    dl.setAttribute('data-price',res[i].price)
	                    dl.setAttribute('data-sellnum',res[i].sellnum)
	                    dl.setAttribute('data-sort',k)
	                    dl.setAttribute('data-addtime',res[i].addtime)
	 					var	html=`<dt class="goto" href="/mobile/column/product_content?id=`+res[i].id+`"><img src="`+res[i].pathname+`" alt=""></dt>
						<dd class="goto" href="/mobile/column/product_content?id=`+res[i].id+`">
							<p>`+res[i].title+`</p><p>`
							if (res[i].keywords){
								for(var j=0;j<res[i].keywords.length;j++){
									html+=`<span>`+res[i].keywords[j]+`</span>`
								}
							}
							html+=`</p><p><span><span>&yen;</span>`
							if(res[i].vprice){
								html+=res[i].vprice
							}else{
								html+=res[i].price
							}
							html+=`</span>`+res[i].sellnum+`人购买</p><p>`
							if(res[i].gname){
								html+=res[i].gname+` `
							}else{
								html+=`{{.system.name}} `
							}
							html+=`<a href="/mobile/store?id=`+res[i].gid+`">进店<i class="iconfont">&#xe7bb;</i></a></p>
						</dd><i class="iconfont scadd" data-minbuy="`+res[i].minbuy+`" data-id="`+res[i].id+'">&#xe619;</i>'
						if (res[i].active==1){
							html+='<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/gbuy.png" class="x">'
							}else if(res[i].active==2){
								html+='<img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/img/sales.png" class="x">'
							}
	                    dl.innerHTML=html
	                    document.getElementsByClassName('PrdLineStyle')[0].appendChild(dl)
	                }
                }else{
                    mui.toast("没有更多了！");
                    $(".dropload-down").remove();
                    me.lock();
                    me.noData();
                }
                me.resetload();
            },
            error: function(xhr, type){
                mui.toast("网络慢，请重新刷新!");
                me.resetload();
            }
        });
    }
});
}
dropload()
mui('body').on('click','.goto',function(){
	var u=this.getAttribute('href')
	if(u){
		window.location.href=u
	}
})
function stopPropagation(e) {  
    if (e.stopPropagation) {  
        e.stopPropagation();  
    } else {  
        e.cancelBubble = true;  
    }  
}  
mui('body').on('click','.scadd',function(e){
	stopPropagation(e)
	var pid=this.getAttribute("data-id")
	var minbuy=this.getAttribute("data-minbuy")
	var data={num:1,pid:pid,minbuy:minbuy}
	mui.get("/mobile/isshopcar",{pid:pid},function(res){
		console.log(res)
		if (minbuy>1 && !res.isshopcar) {
			mui.confirm("该产品为限购产品，起购数量为"+minbuy,"提示",["否","是"],function(res){
				if (res.index==1) {
					mui.post('/mobile/shopcar',data,function(res){
						if(res==2||res==962){
							mui.confirm("您还未登入,请先登入","提示",function(res){
								if(res.index){
									mui.closePopups()
									window.location.href="/mobile/login"
								}
							})
						}else if(res==1){
							mui.toast("添加成功~")
						}else if(res==0){
							mui.toast("网络繁忙,请重试!")
						}else if(res==3){
				          mui.toast('库存不足');
				        }
					})
				} else {
					console.log(res)
				}
			},"div")
		} else {
			mui.post('/mobile/shopcar',data,function(res){
				if(res==2||res==962){
					mui.confirm("您还未登入,请先登入","提示",function(res){
						if(res.index){
							mui.closePopups()
							window.location.href="/mobile/login"
						}
					})
				}else if(res==1){
					mui.toast("添加成功~")
				}else if(res==0){
					mui.toast("网络繁忙,请重试!")
				}else if(res==3){
		          mui.toast('库存不足');
		        }
			})
		}
	})
})
</script>
</html>